import { createRouter, createWebHashHistory } from 'vue-router'

import Layout from '@/page/index/layout.vue'
import NavBox from '@/page/index/navBox.vue'
import PageBox from '@/page/index/index.vue'


//创建路由
const Router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/lamp',
            component: Layout,
            children:[
                {
                    path: '/',
                    component: () => import('@/views/home/index.vue'),
                },
                {
                    path: '/areaLamp',
                    name: 'areaLamp',
                    component: () => import('@/views/areaLamp/index.vue'),
                },
            ]
        },
        {
            path: '/nav',
            component: NavBox,
            children:[
                {
                    path: '/reportManagement',
                    name: 'reportManagement',
                    component: () => import('@/views/reportManagement/index.vue'),
                },
                {
                    path: '/sysManagement',
                    name: 'sysManagement',
                    component: () => import('@/views/sysManagement/index.vue'),
                },
                {
                    path: '/controlSwitchLight',
                    name: 'controlSwitchLight',
                    component: () => import('@/views/sysManagement/controlSwitchLight.vue'),
                },
                {
                    path: '/controlLightsOff',
                    name: 'controlLightsOff',
                    component: () => import('@/views/sysManagement/controlLightsOff.vue'),
                },
                {
                    path: '/regionConfiguration',
                    name: 'regionConfiguration',
                    component: () => import('@/views/sysManagement/regionConfiguration.vue'),
                },
                {
                    path: '/lampInformation',
                    name: 'lampInformation',
                    component: () => import('@/views/lampInformation/index.vue'),
                },
            ]
        },
        {
            path: '/page',
            component: PageBox,
            children:[
                {
                    path: '/userManagement',
                    name: 'userManagement',
                    component: () => import('@/views/userManagement/index.vue'),
                },
                {
                    path: '/operationLog',
                    name: 'operationLog',
                    component: () => import('@/views/operationLog/index.vue'),
                },
                {
                    path: '/electricCurrent',
                    name: 'electricCurrent',
                    component: () => import('@/views/electricCurrent/index.vue'),
                },
                {
                    path: '/currentReport',
                    name: 'currentReport',
                    component: () => import('@/views/operationLog/currentReport.vue'),
                },
                {
                    path: '/maintenanceReport',
                    name: 'maintenanceReport',
                    component: () => import('@/views/operationLog/maintenanceReport.vue'),
                },
                {
                    path: '/inspectionReport',
                    name: 'inspectionReport',
                    component: () => import('@/views/operationLog/inspectionReport.vue'),
                },
                {
                    path: '/nighttimeExpress',
                    name: 'nighttimeExpress',
                    component: () => import('@/views/operationLog/nighttimeExpress.vue'),
                },
                {
                    path: '/energySavingReport',
                    name: 'energySavingReport',
                    component: () => import('@/views/operationLog/energySavingReport.vue'),
                },

            ]
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/page/login/index.vue'),
        },

    ]
})

Router.beforeEach((to, from, next) => {
    if(to.path == '/login'){
        if(localStorage.getItem('userName')){
            next({ path: '/' })
        }
    }else{
        if(!localStorage.getItem('userName')){
            next({ path: '/login' })
        }
    }

    next()
})
export default Router
